package com.hxc.interest.service.impl;

import java.util.List;

import com.hxc.common.utils.DateUtils;
import com.hxc.interest.domain.TReactionUser;
import com.hxc.interest.mapper.TReactionUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hxc.interest.mapper.TReactionThumbsupMapper;
import com.hxc.interest.domain.TReactionThumbsup;
import com.hxc.interest.service.ITReactionThumbsupService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 点赞记录Service业务层处理
 * 
 * @author hxc
 * @date 2021-08-19
 */
@Service
public class TReactionThumbsupServiceImpl implements ITReactionThumbsupService 
{
    @Autowired
    private TReactionThumbsupMapper tReactionThumbsupMapper;
    //事件与用户中间mapper
    @Autowired
    private TReactionUserMapper tReactionUserMapper;


    /**
     * 查询点赞记录列表
     * 
     * @param tReactionThumbsup 点赞记录
     * @return 点赞记录
     */
    @Override
    public List<TReactionThumbsup> selectTReactionThumbsupList(TReactionThumbsup tReactionThumbsup)
    {
        return tReactionThumbsupMapper.selectTReactionThumbsupList(tReactionThumbsup);
    }

    /**
     * 新增点赞记录
     * 
     * @param tReactionThumbsup 点赞记录
     * @return 结果
     */
    @Override
    @Transactional
    public int insertTReactionThumbsup(TReactionThumbsup tReactionThumbsup)
    {
        TReactionUser reactionUser = new TReactionUser();
        reactionUser.setUserId(tReactionThumbsup.getReactionUserId());
        reactionUser.setReactionId(tReactionThumbsup.getReactionId());
        //点赞递增
        reactionUser.setOrderNum(true);
        tReactionUserMapper.updateReactionByNum(reactionUser);
        //添加点赞人员
        tReactionThumbsup.setCreateTime(DateUtils.getNowDate());
        return tReactionThumbsupMapper.insertTReactionThumbsup(tReactionThumbsup);
    }
    /**
     * 删除点赞记录信息
     *
     * @return 结果
     */
    @Override
    public int deleteTReactionThumbsup(TReactionThumbsup tReactionThumbsup)
    {
        TReactionUser reactionUser = new TReactionUser();
        reactionUser.setUserId(tReactionThumbsup.getReactionUserId());
        reactionUser.setReactionId(tReactionThumbsup.getReactionId());
        //点赞递减
        reactionUser.setOrderNum(false);
        tReactionUserMapper.updateReactionByNum(reactionUser);
        return tReactionThumbsupMapper.deleteTReactionThumbsup(tReactionThumbsup);
    }

}
